package com.learning.springmybatis.controller;

import com.learning.springmybatis.entity.User;
import com.learning.springmybatis.service.UserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@Controller
public class UserController {

    private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }

    @GetMapping("/{id}")
    public String getName(@PathVariable("id") Integer id, Model model) {
        System.out.println(id);
        User user = userService.getName(id);
        System.out.println(user);
        model.addAttribute("user",user);
        return "user";
    }
}
